package DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mysql.jdbc.CallableStatement;
import com.mysql.jdbc.PreparedStatement;

import Model.Convenio;
import Model.Paciente;
import Utils.Conexao;

public class ConvenioDAO {
	
	public static ArrayList<Convenio> GetConvenioArrayList()
	{
		ArrayList<Convenio> arrConvenios = new ArrayList<Convenio>(); 
		Connection con  = Conexao.getConection();
		try
		{
			String mysqlCall = "call spc_select_convenios()";
			CallableStatement call = (CallableStatement) con.prepareCall(mysqlCall);
			ResultSet rs = call.executeQuery();
			
			while(rs.next())
			{
				Convenio convenio = ConvenioDAO.setInstance(rs);
				arrConvenios.add(convenio);
			}
			
			con.close();
			call.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		
		return arrConvenios;		
	}
	
	public static Convenio setInstance(ResultSet res) throws SQLException
	{
		Convenio convenio = new Convenio(); 
		convenio.setIdConvenio(res.getInt("id_convenio"));
		convenio.setNome_convenio(res.getString("nome_convenio"));
		return convenio;
	}	
	
}
